package com.kuaimacode.kframework.api.controller.common;

import com.kuaimacode.kframework.api.controller.BaseController;
import com.kuaimacode.kframework.api.service.UploadService;
import com.kuaimacode.kframework.api.vo.response.UploadImgResp;
import com.kuaimacode.kframework.common.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author qinyong
 * @Title:
 * @Package com.kuaimacode.kframework.api.controller.common
 * @Description: created by IntelliJ IDEA
 * @date 2019-03-16 21:29
 */
@RestController
@RequestMapping("upload")
@Api(tags = "文件上传", description = "文件上传相关api")
public class UploadController extends BaseController {

    @Autowired
    private UploadService uploadService;

    /*@ApiOperation(value = "上传头像图片", notes="上传头像图片")
    @PostMapping("/uploadHeadImg")
    @ApiImplicitParam(name = "img", value = "base64图片数据", required = true, dataType = "string")
    public JsonResult<UploadImgResp> uploadHeadImg(@RequestBody String img) {
        return JsonResult.success(uploadService.uploadHeadImg(img, getUserId()));
    }*/

    @ApiOperation(value = "上传头像图片", notes = "上传头像图片")
    @PostMapping("/uploadHeadImgFile")
    @ApiImplicitParam(name = "file", value = "图片文件", required = true)
    public JsonResult<UploadImgResp> uploadHeadImg(@RequestParam("file") MultipartFile file) {
        return JsonResult.success(uploadService.uploadImg(file, getUserId()));
    }

    /*@ApiOperation(value = "上传图片", notes="上传图片")
    @PostMapping("/uploadImg")
    @ApiImplicitParam(name = "img", value = "base64图片数据", required = true, dataType = "string")
    public JsonResult<UploadImgResp> uploadImg(@RequestBody String img) {
        return JsonResult.success(uploadService.uploadImg(img,getUserId()));
    }*/

    @ApiOperation(value = "上传图片", notes = "上传图片")
    @PostMapping(value="/uploadImg", headers = "content-type=multipart/form-data")
   // @ApiImplicitParam(name = "file", value = "图片文件" ,required = true)
    public JsonResult<UploadImgResp> uploadImg(@ApiParam(value = "上传的文件") @RequestParam("file") MultipartFile file) {
        return JsonResult.success(uploadService.uploadImg(file, getUserId()));
    }
}
